import $axios from 'utils/Request'

/**
 * 登录
 * @param {loginName, loginPwd} data 
 */
export const login = data => {
    return $axios({
        url: '/api/user-acc-do/v1/login',
        method: 'post',
        data
    });
}

/**
 * 注册
 * @param {loginName, loginPwd, code} data 
 */
export const reg = data => {
    return $axios({
        url: '/api/user-acc-do/v1/reg',
        method: 'post',
        data
    });
}


/**
 * 获取用户详情
 * @param {*} data 
 */
export const getUserById = data => {
    return $axios({
        url: '/api/user-do/v1/' + data.id,
        method: 'get',
        data
    });
}

/**
 * 获取用户列表
 */
export const getUserPage = data => {
    return $axios({
        url: '/api/user-do/v1',
        method: 'get',
        data
    });
}

/**
 * 保存用户
 * @param {*} data 
 */
export const saveUser = data => {
    return $axios({
        url: '/api/user-do/v1',
        method: 'post',
        data
    });
}

/**
 * 删除用户
 * @param {*} data 
 */
export const deleteUserById = data => {
    return $axios({
        url: '/api/user-do/v1/' + data.id,
        method: 'delete',
        data
    });
}


/**
 * 修改密码
 * @param {newPwd, confirmNewPwd} data 
 */
export const updatePwd = data => {
    return $axios({
        url: '/api/user-acc-do/v1/updatePwd',
        method: 'put',
        data
    });
}


/**
 * 修改用户信息
 * @param {*} data 
 */
export const updateUserById = data => {
    return $axios({
        url: '/api/user-do/v1/' + data.id,
        method: 'put',
        data
    });
}

/**
 * 单一字段修改
 * @param {*} data 
 */
export const patchUserById = data => {
    return $axios({
        url: '/api/user-do/v1/' + data.id,
        method: 'patch',
        data
    });
}


/**
 * 得到当前用户已经授权的角色
 * @param {*} data 
 */
export const getRuleIdListByUserId = data => {
    return $axios({
        url: '/api/user-rule-do/v1/' + data.id,
        method: 'get',
        data
    });
}

/**
 * 保存角色授权信息
 * @param {*} data 
 */
export const saveUserRule = data => {
    return $axios({
        url: '/api/user-rule-do/v1',
        method: 'post',
        data
    });
}

/**
 * 等到当前登录用户已经授权的资源，并已tree形式展示
 * @param {*} data 
 */
export const getHasPermissionList = data => {
    return $axios({
        url: '/api/user-rule-do/v1/getHasPermissionList',
        method: 'get',
        data
    });
}